//
// Created by LoveHoneyYou on 2024-11-16.
//

#ifndef WEBSERVER_CHANNEL_H
#define WEBSERVER_CHANNEL_H
#include <functional>



//文件描述符对应事件类型
enum class FD_Event
{
    TimeOut = 0x01,
    ReadEvent = 0x02,
    WriteEvent = 0x04
};


class Channel
{
public:
    //包装回调事件
    using HandleFunc = std::function<int(void*)>;

    Channel(int fd, const FD_Event& event,const HandleFunc& read_func,const HandleFunc& write_func,const HandleFunc& destory_func, void* args);

    //写事件
    void Write_Event_Enable(bool flag);

    //判断是否需要检测文件描述符的写事件
    bool Is_Check_Write_Event();

    inline int Get_Event()
    {
        return event_;
    }

    inline int Get_Socket()
    {
        return fd_;
    }

    inline const void* Get_Arg() const
    {
        return args_;
    }


public:
    HandleFunc read_callback_;
    HandleFunc write_callback_;
    HandleFunc destroy_callback_;

private:
    int fd_;
    int event_;
    void* args_;
};





#endif//WEBSERVER_CHANNEL_H
